<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<button type="button" onclick="Doone(event);">抽一次</button>
		<table border="" cellspacing="" cellpadding="10px" bgcolor="aqua">
			<tr>
				<td id='JP1'>冰箱</td>
				<td id='JP2'>空调</td>
				<td id='JP3'>洗衣机</td>
			</tr>
			<tr>
				<td id='JP4'>热水器</td>
				<td id='JP5'>电视</td>
				<td id='JP6'>电脑</td>
			</tr>
			<tr>
				<td id='JP7'>电饭煲</td>
				<td id='JP8'>微波炉</td>
				<td id='JP9'>电风扇</td>
			</tr>
		</table>
	</body>
	<script type="text/javascript">
		function Doone(event){
			event.target.innerText = '抽奖中...';
			var allTds = document.getElementsByTagName('td');
			//每次抽奖样式回到开始的样式
			for(var i=0;i<allTds.length;i++){
				allTds[i].style.backgroundColor = 'aqua';
			}
			setInterval(function(){

				var randNum = getrandomNum();
				console.log('公布抽奖结果：'+randNum);
				document.getElementById('JP'+randNum).style.backgroundColor = 'red';
				event.target.innerText = '重新抽一次';
			},5000);
		}
		function getrandomNum(){
			//随机数定义
			while(true){
				var randNum = Math.floor(Math.random()*10);
				if(randNum!=0){
					return randNum;
				}
			}
			
		}
	</script>
</html>
